{% extends "master.html" %}
{% block content %}
    <!-- OPEN EXAMS -->
        <h2>Open exams ({{ open_exams.count }})</h2>
    <table width="100%">
        <tr>
            <td><b>Exam</b></td>
            <td><b>Created</b></td>
            <td><b>Deadline</b></td>
            <td><b>Author</b></td>
            <td></td>
            <td></td>

        </tr>
       {% for oexam in open_exams %}
           <tr>
               <td>{{ oexam.name }}</td>
               <td><time datetime="">{{ oexam.created }}</time></td>
               <td><time datetime="">{{ oexam.deadline }}</time></td>
               <td>{{ oexam.author }}</td>
               <td>
                   {% if not request.teacher %}
                    <button onclick="document.location.href='/view/{{ oexam.id }}'">Take exam</button>
                   {% endif %}
               </td>
               <td>
                   {% if request.teacher %}
                    <a href="/delete/{{ oexam.id }}" onclick="return confirm('Do you really want to delete?')">X</a>
                   {% endif %}
               </td>
           </tr>
        {% endfor %}
    </table>

    <!-- COMPLETED EXAMS -->
    <h2>Completed exams ({{ comp_exams.count }})</h2>
    <table width="100%">
        <tr>
            <td><b>Exam</b></td>
            <td><b>Created</b></td>
            <td><b>Deadline</b></td>
            <td><b>Author</b></td>
            {% if request.teacher %}
                <td><b>Student</b></td>
            {% endif %}
            <td><b>Grade</b></td>
            <td></td>

        </tr>
        {% for dexam in comp_exams %}
        <tr>
            <td>{{ dexam.name }}</td>
            <td><time datetime="">{{ dexam.created }}</time></td>
            <td><time datetime="">{{ dexam.deadline }}</time></td>
            <td>{{ dexam.author }}</td>
            {% if request.teacher %}
                <td>{{ dexam.username }}</td>
            {% endif %}
            <td>{{ dexam.grade|floatformat }}</td>
            <td>
                {% if request.teacher %}
                <a href="/delete/{{ dexam.id }}" onclick="return confirm('Do you really want to delete?')">X</a>
                {% endif %}
            </td>
        </tr>
        {% endfor %}
    </table>

    <!-- EXPIRED EXAMS -->
        <h2>Expired exams ({{ expired_exams.count }})</h2>
    <table width="100%">
        <tr>
            <td><b>Exam</b></td>
            <td><b>Created</b></td>
            <td><b>Deadline</b></td>
            <td><b>Author</b></td>
            <td></td>

        </tr>
        {% for eexam in expired_exams %}
        <tr>
            <td>{{ eexam.name }}</td>
            <td><time datetime="">{{ eexam.created }}</time></td>
            <td><time datetime="">{{ eexam.deadline }}</time></td>
            <td>{{ eexam.author }}</td>
            <td>
                {% if request.teacher %}
                <a href="/delete/{{ eexam.id }}" onclick="return confirm('Do you really want to delete?')">X</a>
                {% endif %}
            </td>
        </tr>
        {% endfor %}
    </table>

{% endblock %}